//
//  SongMenuViewController.m
//  SinceLe
//
//  Created by 李元喜 on 15/11/14.
//  Copyright © 2015年 李元喜. All rights reserved.
//

#import "SongMenuViewController.h"
#import "SongMenuCollectionViewCell.h"
#import "NetWorkHandle.h"
#import "Macrocs.h"
#import "MusicModel.h"
#import <UIImageView+WebCache.h>
#import "MusicPageViewController.h"
//#import "DetailsPageController.h"
@interface SongMenuViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionViewFlowLayout *Flow;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) NSMutableArray *dataArray;



@end

@implementation SongMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadcollectionView];
//    [self loadSongData];
}

-(void)loadcollectionView{
    
    _Flow = [[UICollectionViewFlowLayout alloc] init];
    self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:self.Flow];
 
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
//    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"CELL"];
    
    //布局每一个item的样式
    self.Flow.itemSize = CGSizeMake(150, 200);
    self.Flow.minimumLineSpacing = 20;
    self.Flow.minimumInteritemSpacing = 20;
    //设置上下左右间距
    self.Flow.sectionInset = UIEdgeInsetsMake(10,20, 150,20);
    
    UINib *nib = [UINib nibWithNibName:@"SongMenuCollectionViewCell" bundle:nil];
    [self.collectionView registerNib:nib forCellWithReuseIdentifier:@"cell"];
    
    [self.view addSubview:self.collectionView];
    
    
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return _dataArray.count;
}


#pragma mark -----第二个界面
//
//-(void)loadSongData{
//    
//    NSString *Str = [NSString stringWithFormat:KsongMenu];
//    [NetWorkHandle getDataWithURLString:Str compare:^(id object) {
//        _dataArray = [NSMutableArray array];
//        NSDictionary* dic = object;
//        NSArray* arr = dic[@"content"];
//        for (NSDictionary* a in arr) {
//            MusicModel * model = [[MusicModel alloc] init];
//            
//            [model setValuesForKeysWithDictionary:a];
//            
//            [_dataArray addObject:model];
//        }
//        [_collectionView reloadData];
//        
//    }];
//    
//}



-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    SongMenuCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    MusicModel *model = [[MusicModel alloc]init];
    model = self.dataArray[indexPath.row];
//  
//    cell.SongLabel.text = model.listenum;
//    cell.SongLabeltitle.text = model.title;
//    [cell.Songimage sd_setImageWithURL:[NSURL URLWithString:model.pic_300]];
//    
    return cell;
}

//触摸时间 传值
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    MusicPageViewController *Musicpage = [[MusicPageViewController alloc]init];
    MusicModel *model = _dataArray[indexPath.row];
    
//    Musicpage.listIdStr = model.listid;
//    
   [self.navigationController pushViewController:Musicpage animated:YES];

}

////UICollectionView被选中时调用的方法
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{

    
    return YES;
}


- (void)collectionView:(UICollectionView *)colView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell* cell = [colView cellForItemAtIndexPath:indexPath];
    
    [cell setBackgroundColor:[UIColor purpleColor]];
}

- (void)collectionView:(UICollectionView *)colView  didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell* cell = [colView cellForItemAtIndexPath:indexPath];
    
    [cell setBackgroundColor:[UIColor yellowColor]];
    
}












- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
